package com.mmall.controller.backstage;

import com.github.pagehelper.PageInfo;
import com.mmall.common.ServerResponse;
import com.mmall.service.IOrderService;
import com.mmall.service.IUserService;
import com.mmall.vo.OrderVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * 管理员订单控制层
 * Created by qezhhnjy on 2017/10/18-22:22.
 */
@Controller
@RequestMapping("/manager/order/")
public class OrderManagerController {

    @Resource
    private IUserService iUserService;

    @Resource
    private IOrderService iOrderService;

    /**
     * 管理员查询订单列表
     *
     * @param session  当前管理员
     * @param pageNum  当前页数
     * @param pageSize 每页个数
     * @return 响应对象
     */
    @ResponseBody
    @RequestMapping(value = "order_list.do", method = RequestMethod.POST)
    public ServerResponse<PageInfo<OrderVo>> orderList(HttpSession session,
                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        ServerResponse response = iUserService.adminCheck(session);
        if (response.isSuccess()) {
            return iOrderService.managerList(pageNum, pageSize);
        }
        return ServerResponse.createByErrorMessage(response.getMsg());
    }

    /**
     * 管理员指定订单号详情查询
     *
     * @param session 当前管理员
     * @param orderNo 订单号
     * @return 响应对象
     */
    @ResponseBody
    @RequestMapping(value = "order_detail.do", method = RequestMethod.POST)
    public ServerResponse<OrderVo> orderDetail(@RequestParam HttpSession session, @RequestParam Long orderNo) {
        ServerResponse response = iUserService.adminCheck(session);
        if (response.isSuccess()) {
            return iOrderService.managerDetail(orderNo);
        }
        return ServerResponse.createByErrorMessage(response.getMsg());
    }

    @ResponseBody
    @RequestMapping(value = "order_search.do", method = RequestMethod.POST)
    public ServerResponse<PageInfo<OrderVo>> orderSearch(@RequestParam HttpSession session, @RequestParam Long orderNo) {
        return null;
    }

    @ResponseBody
    @RequestMapping(value = "send_order.do", method = RequestMethod.POST)
    public ServerResponse<String> orderSend(@RequestParam HttpSession session, @RequestParam Long orderNo) {
        return null;
    }


}
